﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SoundPlugin.Custom_Buttons;
using System.IO;
using System.Threading;

namespace SoundPlugin
{
    /// <summary>
    /// Interaction logic for SoundToShapeMenu.xaml
    /// </summary>
    public partial class SoundToShapeMenu : UserControl
    {
        private TriangleButton rightButton;

        public TriangleButton RightButton
        {
            get { return rightButton; }
            set { rightButton = value; }
        }
        private TriangleButton leftButton;

        public TriangleButton LeftButton
        {
            get { return leftButton; }
            set { leftButton = value; }
        }
        private List<FileInfo> soundfiles;
        private ListBox soundListBox;

        public ListBox SoundListBox
        {
            get { return soundListBox; }
            set { soundListBox = value; }
        }
        private ListBoxItem selectedItem;

        private Button finishedButton;

        public Button FinishedButton
        {
            get { return finishedButton; }
            set { finishedButton = value; }
        }

        private Button assignRandomlyButton;

        public Button AssignRandomlyButton
        {
            get { return assignRandomlyButton; }
            set { assignRandomlyButton = value; }
        }

        public SoundToShapeMenu(List<FileInfo> soundfiles)
        {
            InitializeComponent();
            this.soundfiles = soundfiles;
            this.Width = 500;
            this.Height = 500;
            RowDefinition topRow = new RowDefinition();
            topRow.Height = new GridLength(1, GridUnitType.Auto);
            RowDefinition middleRow = new RowDefinition();
            middleRow.Height = new GridLength(1, GridUnitType.Auto);
            RowDefinition bottomRow = new RowDefinition();
            bottomRow.Height = new GridLength(1, GridUnitType.Auto);
            ColumnDefinition column = new ColumnDefinition();
            column.Width = new GridLength(500, GridUnitType.Pixel);

            this.MainGrid.ColumnDefinitions.Add(column);
            this.MainGrid.RowDefinitions.Add(topRow);
            this.MainGrid.RowDefinitions.Add(middleRow);
            this.MainGrid.RowDefinitions.Add(bottomRow);

            this.finishedButton = new Button();
            this.finishedButton.Width = 200;
            this.finishedButton.Height = 40;
            this.finishedButton.Content = "Finished";
            this.finishedButton.BorderThickness = new Thickness(10);
            this.finishedButton.BorderBrush = Brushes.Transparent;
            this.finishedButton.Foreground = Brushes.Black;
            this.finishedButton.Background = Brushes.LightGreen;
            this.finishedButton.Opacity = 0.5;

            this.assignRandomlyButton = new Button();
            this.assignRandomlyButton.Width = 200;
            this.assignRandomlyButton.Height = 40;
            this.assignRandomlyButton.Content = "Random";
            this.assignRandomlyButton.BorderThickness = new Thickness(10);
            this.assignRandomlyButton.BorderBrush = Brushes.Transparent;
            this.assignRandomlyButton.Foreground = Brushes.Black;
            this.assignRandomlyButton.Background = Brushes.LightGreen;
            this.assignRandomlyButton.Opacity = 0.5;

            this.finishedButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this.finishedButton.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            this.assignRandomlyButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            this.assignRandomlyButton.VerticalAlignment = System.Windows.VerticalAlignment.Top;

            this.BottomStackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this.BottomStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.BottomStackPanel.Orientation = Orientation.Horizontal;
            this.BottomStackPanel.Children.Add(this.finishedButton);
            Rectangle rectangle = new Rectangle();
            rectangle.Fill = Brushes.Transparent;
            rectangle.Width = 50;
            this.BottomStackPanel.Children.Add(rectangle);
            this.BottomStackPanel.Children.Add(this.assignRandomlyButton);

            this.MainStackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this.MainStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.MainStackPanel.Orientation = Orientation.Horizontal;
            this.soundListBox = new ListBox();
            this.soundListBox.Background = Brushes.Transparent;
            this.soundListBox.Opacity = 0.8;
            //this.soundListBox.ItemsSource = this.soundfiles;
            foreach (FileInfo fileInfo in this.soundfiles)
            {
                ListBoxItem item = new ListBoxItem();
                item.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center;
                item.Height = 50;
                item.Content = fileInfo;
                item.FontFamily = new FontFamily("Verdana");
                item.FontSize = 18;
                item.Opacity = 0.5;
                item.Padding = new Thickness(10);
                item.BorderThickness = new Thickness(5);
                item.BorderBrush = Brushes.Transparent;
                item.Background = Brushes.PaleGreen;
                this.soundListBox.Items.Add(item);
            }
            this.selectedItem = (ListBoxItem)this.soundListBox.SelectedItem;
            this.soundListBox.Width = 200;
            this.soundListBox.Height = 300;
            this.soundListBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            this.soundListBox.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            this.leftButton = new TriangleButton(TriangleButton.TriangleDirection.Left, System.Drawing.Color.LightGreen, System.Drawing.Color.DarkGreen, 5);
            this.leftButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            this.leftButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            this.rightButton = new TriangleButton(TriangleButton.TriangleDirection.Right, System.Drawing.Color.LightGreen, System.Drawing.Color.DarkGreen, 5);
            this.rightButton.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            this.rightButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;

            leftButton.Opacity = 0.5;
            rightButton.Opacity = 0.5;
            this.MainStackPanel.Children.Add(this.leftButton);
            this.MainStackPanel.Children.Add(this.soundListBox);
            this.MainStackPanel.Children.Add(this.rightButton);

            Grid.SetRow(MainStackPanel, 1);
            Grid.SetColumn(MainStackPanel, 0);
            Grid.SetRow(BottomStackPanel, 2);
            Grid.SetColumn(BottomStackPanel, 0);

        }

    }
}
